package com.xc.quickstart.mq.listener;

import com.alibaba.fastjson.JSON;
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.xc.quickstart.mq.listener.vo.DemoMqVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Slf4j
@Component
public class SampleMqListener extends BaseMqListener {


    @Override
    public String getGroupId() {
        return "GID_QUICKSTART_CHANGED";
    }

    @Override
    public String getTopic() {
        return "T_QUICKSTART_CHANGED";
    }

    @Override
    protected String getListenerName() {
        return "DEMO消息监听";
    }

    @Override
    protected Action doConsume(Message message, ConsumeContext context) {
        String messageBody = new String(message.getBody(), StandardCharsets.UTF_8);
        DemoMqVO demoMqVO = JSON.parseObject(messageBody, DemoMqVO.class);

        return Action.CommitMessage;
    }

}
